package fr.upmc.i3s.upmcontact.contents;

import java.util.Date;
import java.util.Locale;

public class User extends Content {
	
	private static final long serialVersionUID = 993357275125706889L;
	
	private String username;
	private String password;
	private String email;
	private boolean keepLogged;
	
	public User() {
		super();
		this.username = null;
		this.password = null;
		this.email = null;
		this.keepLogged = false;
	}

	public User(String id, Date createdAt, Date updatedAt,
				String username, String password, String email, boolean keepLogged) {
		super(id, createdAt, updatedAt);
		if(username != null) { this.username = username.toLowerCase(Locale.getDefault()); }
		this.password = password;
		this.email = email;
		this.keepLogged = keepLogged;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		if(username != null) { this.username = username.toLowerCase(Locale.getDefault()); }
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	
	public boolean isKeepLogged() {
		return keepLogged;
	}

	public void setKeepLogged(boolean keepLogged) {
		this.keepLogged = keepLogged;
	}
	
	@Override
	public int hashCode() {
		return super.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (email == null) {
			if (other.email != null)
				return false;
		} else if (!email.equals(other.email))
			return false;
		if (keepLogged != other.keepLogged)
			return false;
		if (password == null) {
			if (other.password != null)
				return false;
		} else if (!password.equals(other.password))
			return false;
		if (username == null) {
			if (other.username != null)
				return false;
		} else if (!username.equals(other.username))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return super.toString() + " User [username=" + username + ", password=" + "******"
				+ ", email=" + email + ", keepLogged=" + keepLogged + "]";
	}

}
